#pragma once

#include<pthread.h>
#include<iostream>

using namespace std;

class Task
{
  public:
  Task()
  {}
  Task(int x,int y,char op)
    :_x(x)
    ,_y(y)
    ,_op(op)
  {}
  void run()
  {
    int z=0;
    switch(_op)
    {
      case'+':
        z=_x+_y;
        break;
      case'-':
        z=_x-_y;
        break;
      case'*':
        z=_x*_y;
        break;
      case'/':
        if(_y==0)cerr<<"div zero"<<endl;
        if(_y!=0)z=_x/_y;
        break;
      case'%':
        if(_y==0)cerr<<"mod zero"<<endl;
        if(_y!=0)z=_x%_y;
        break;
      default:
        cerr<<"operator error"<<endl;
        break;
    }
    cout<<"thread: ["<<pthread_self()<<"]"<<_x<< _op <<_y<<" = "<< z <<endl;
  }
  ~Task()
  {}
  private:
  int _x;
  int _y;
  char _op;

};
